package problem;

public class S_108 {
    //将有序数组转换为二叉搜索树
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    //二分
    class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            return toBST(nums,0,nums.length-1);
        }
        public TreeNode toBST(int[] nums,int left,int right){
            if(left>right) return null;
            int mid=left+(right-left)/2;
            TreeNode root=new TreeNode(nums[mid]);
            root.left=toBST(nums,left,mid-1);
            root.right=toBST(nums,mid+1,right);
            return root;
        }
    }
}
